<?php
class Category extends CategoryPeer
{
	function Category()
	{
		parent::CategoryPeer();
	}
	
	public static function getAllCategories()
	{
		$database = new Database();
		$query = "SELECT id FROM Category";
		$result = $database->query($query);
		$ids = $database->fetch_array($result);
		$tours = array();
		foreach ($ids as $id) {
			$t = new Category();
			$t->select($id['id']);
			$tours[] = $t;
		}
		return $tours;
	}
	
	function getAllToursInCategory($checkActive=true, $active=1, $orderby = 'tour_id DESC', $limit=NULL)
	{
		$db = new DataBase();
		$sql = "SELECT tour_id FROM tour_category WHERE category_id = ".$this->getid()." GROUP BY tour_id ORDER BY $orderby ";
		if ($limit)
			$sql .= " LIMIT $limit";
		$result = $db->query($sql);
		$ids = $db->fetch_array($result);
		$tours = array();
		foreach ($ids as $id) {
			$tour = new Tour();
			$tour->select($id['tour_id']);
			if ($checkActive) {
				if ($tour->getactive() == $active)
					$tours[] = $tour;
			} else
				$tours[] = $tour;
		}
		return $tours;
	}
	
	function getAllTourCategories()
	{
		$db = new DataBase();
		$sql = "SELECT id FROM tour_category WHERE category_id = ".$this->getid().";";
		$result = $db->query($sql);
		$ids = $db->fetch_array($result);
		$categories = array();
		foreach ($ids as $id) {
			$category = new Category();
			$category->select($id['id']);
			$categories[] = $category;
		}
		return $categories;
	}
}
?>